﻿using BCCommon;
using BCCommon.TMS.Transport;
using BCDto.TMS.VehicleTransportBusinessConfig;
using BCService.TMS.VehicleTransportBusinessConfig;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.VehicleTransportBusinessConfig
{
    /// <summary>
    /// 车辆运输业务配置
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class VehicleTransportBusinessConfigController : ManagementBaseController
    {
        private readonly IVehicleTransportBusinessConfigService vehicleTransportBusinessConfigService;

        public VehicleTransportBusinessConfigController(IVehicleTransportBusinessConfigService vehicleTransportBusinessConfigService)
        {
            this.vehicleTransportBusinessConfigService = vehicleTransportBusinessConfigService;
        }

        /// <summary>
        /// 添加车辆运输业务配置
        /// </summary>
        /// <param name="requestDto">车辆运输业务配置新增信息</param>
        /// <response code="201">添加车辆运输业务配置</response>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(VehicleTransportBusinessConfigViewDto), 201)]
        [Log("添加车辆运输业务配置")]
        public IActionResult Post([FromBody] VehicleTransportBusinessConfigRequestDto requestDto)
        {
            var result = this.vehicleTransportBusinessConfigService.Create(this.Admin, requestDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取车辆运输业务配置
        /// </summary>
        /// <param name="transportBusiness">运输业务</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">获取车辆运输业务配置</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<VehicleTransportBusinessConfigViewDto>), 200)]
        public IActionResult Query([FromQuery(Name = "transport_business")] TransportBusinessType? transportBusiness,
            [FromQuery(Name = "page_index")]int pageIndex = 1,
            [FromQuery(Name = "page_size")]int pageSize = 10)
        {
            var result = this.vehicleTransportBusinessConfigService.Query(this.Admin, transportBusiness, pageIndex, pageSize);
            return this.Ok(result);
        }
        /// <summary>
        /// 获取车辆运输业务配置(仅获取基本业务配置且已启用的)
        /// </summary>
        /// <response code="200">获取车辆运输业务配置</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<VehicleTransportBusinessConfigDto>), 200)]
        public IActionResult List()
        {
            var result = this.vehicleTransportBusinessConfigService.GetList();
            return this.Ok(result);
        }

        /// <summary>
        /// 获取所有车辆运输业务配置
        /// </summary>
        /// <response code="200">获取所有车辆运输业务配置</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<VehicleTransportBusinessConfigDto>), 200)]
        public IActionResult AllList([FromQuery(Name = "enabled")] bool? enabled)
        {
            var result = this.vehicleTransportBusinessConfigService.GetAllList(enabled);
            return this.Ok(result);
        }

        /// <summary>
        /// 修改车辆运输业务配置
        /// </summary>
        /// <param name="vehicleTransportBusinessConfigId">车辆运输业务配置Id</param>
        /// <param name="putDto">车辆运输业务配置修改信息</param>
        /// <response code="200">修改车辆运输业务配置</response>
        /// <returns></returns>
        [HttpPut("{vehicle_transport_business_config_id}")]
        [ProducesResponseType(typeof(VehicleTransportBusinessConfigViewDto), 200)]
        [Log("修改车辆运输业务配置")]
        public IActionResult Put([FromRoute(Name = "vehicle_transport_business_config_id")] int vehicleTransportBusinessConfigId,
            [FromBody] VehicleTransportBusinessConfigPutDto putDto)
        {
            var result = this.vehicleTransportBusinessConfigService.Update(this.Admin, vehicleTransportBusinessConfigId, putDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 删除车辆运输业务配置
        /// </summary>
        /// <param name="vehicleTransportBusinessConfigId">车辆运输业务配置Id</param>
        /// <response code="204">删除车辆运输业务配置</response>
        /// <returns></returns>
        [HttpDelete("{vehicle_transport_business_config_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        [Log("删除车辆运输业务配置")]
        public IActionResult Delete([FromRoute(Name = "vehicle_transport_business_config_id")]int vehicleTransportBusinessConfigId)
        {
            this.vehicleTransportBusinessConfigService.Delete(this.Admin, vehicleTransportBusinessConfigId);
            return NoContent();
        }

        /// <summary>
        /// 启用/禁用车辆运输业务配置
        /// </summary>
        /// <param name="vehicleTransportBusinessConfigId">车辆运输业务配置Id</param>
        /// <param name="enabled">是否启用</param>
        /// <response code="200">启用/禁用车辆运输业务配置</response>
        /// <returns></returns>
        [HttpPut("[action]/{vehicle_transport_business_config_id}/{enabled}")]
        [ProducesResponseType(typeof(VehicleTransportBusinessConfigViewDto), 200)]
        [Log("启用/禁用车辆运输业务配置")]
        public IActionResult Enabled([FromRoute(Name = "vehicle_transport_business_config_id")] int vehicleTransportBusinessConfigId,
            [FromRoute(Name = "enabled")] bool enabled)
        {
            var result = this.vehicleTransportBusinessConfigService.UpdateEnabled(this.Admin, vehicleTransportBusinessConfigId, enabled);
            return this.Ok(result);
        }
    }
}
